/*
 * JListRenderer.java
 *
 * Created on 17 de Junho de 2007, 17:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.jerm.Interface.JGraph_Diagrama;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author tiagofalcao
 */
public class JListRenderer extends JLabel implements ListCellRenderer {
    ImageIcon icon;
    ImageIcon selectIcon;
    //Color selectCouleur = Color.LIGHT_GRAY;

    public JListRenderer(){
      icon  = new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/key.gif"));
      selectIcon  = new ImageIcon(getClass().getClassLoader().getResource("org/jerm/Interface/Icones/port.gif"));
    }

    public Component getListCellRendererComponent(
      JList list,
      Object value,            // valeur à afficher
      int index,               // indice d'item
      boolean isSelected,      // l'item est-il sélectionné
      boolean cellHasFocus)    // La liste a-t-elle le focus
    {
        String s = value.toString();
        JListItem v=(JListItem)value;
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getForeground());
            //setForeground(selectCouleur);
            //setText(s+"  "+index);
            setText(s+"  <<<");
            setIcon(v.icon);
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
            setText(s);       
            setIcon(v.selection_icon);
          }
          setEnabled(list.isEnabled());
          setFont(list.getFont());
          setOpaque(true);
          return this;
    }
}
